/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 15:09:08
 * @FilePath: \bg-vben\src\api\iot\admin\driver\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type {
  DriverInputDto,
  DriverInputDtoSimple,
  DriverNode,
  DriverOutputDto,
  DriverOutputDtoSimple,
  DriverPackageInputDto,
  DriverPackageOutputDto,
} from './model';

import type { ErrorMessageMode, PageData } from '#/request';

import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** IoT驱动枚举 */
enum Api {
  /** 读取驱动 */
  Read = '/api/iot/admin/driver/read',
  /** 读取驱动简单信息 */
  ReadSimple = '/api/iot/admin/driver/readSimple',
  /** 读取驱动节点 */
  ReadNodes = '/api/iot/admin/driver/readNodes',

  /** 新增驱动 */
  Create = '/api/iot/admin/driver/create',
  /** 更新驱动 */
  Update = '/api/iot/admin/driver/update',
  /** 删除驱动 */
  Delete = '/api/iot/admin/driver/delete',

  /** 更新驱动简单信息 */
  UpdateSimple = '/api/iot/admin/driver/updateSimple',

  /** 获取驱动程序包 */
  GetPackage = '/api/iot/admin/driver/getPackage',
  /** 设置驱动程序包 */
  SetPackage = '/api/iot/admin/driver/setPackage',
}

// #region 读取驱动
/**
 * 读取驱动
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readDriver(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<DriverOutputDto>>(
    {
      url: Api.Read,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取驱动简单信息
/**
 * 读取驱动简单信息
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readDriverSimple(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<DriverOutputDtoSimple>>(
    {
      url: Api.ReadSimple,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取驱动节点
/**
 * 读取驱动节点
 * @param mode 错误消息模型
 */
export function readDriverNodes(mode: ErrorMessageMode = 'message') {
  return request.get<DriverNode[]>(
    {
      url: Api.ReadNodes,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 新增驱动
/**
 * 新增驱动
 * @param dtos 驱动DTO
 * @param mode 错误消息模型
 */
export function createDriver(dtos: DriverInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Create,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 更新驱动
/**
 * 更新驱动
 * @param dtos 驱动DTO
 * @param mode 错误消息模型
 */
export function updateDriver(dtos: DriverInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Update,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 删除驱动
/**
 * 删除驱动
 * @param ids 驱动编号
 * @param mode 错误消息模型
 */
export function deleteDriver(ids: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Delete,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 更新驱动简单信息
/**
 * 更新驱动简单信息
 * @param dtos 驱动DTO
 * @param mode 错误消息模型
 */
export function updateDriverSimple(dtos: DriverInputDtoSimple[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdateSimple,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 获取驱动程序包
/**
 * 获取驱动程序包
 * @param driverId 驱动编号
 * @param mode 错误消息模型
 */
export function getDriverPackage(driverId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<DriverPackageOutputDto>(
    {
      url: Api.GetPackage,
      params: { driverId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 设置驱动程序包
/**
 * 设置驱动程序包
 * @param dtos 驱动程序包DTO
 * @param mode 错误消息模型
 */
export function setDriverPackage(dtos: DriverPackageInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetPackage,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
